package zx.x.modules.yshbms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import zx.x.common.utils.PageUtils;
import zx.x.common.utils.Query;
import zx.x.modules.yshbms.dao.CommunityDao;
import zx.x.modules.yshapp.entity.CommunityEntity;
import zx.x.modules.yshbms.service.CommunityService;

import java.util.Map;


@Service("communityService")
public class CommunityServiceImpl extends ServiceImpl<CommunityDao, CommunityEntity> implements CommunityService {
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String communityName = (String) params.get("communityName");
        if(communityName == null){
            IPage<CommunityEntity> page = this.page(
                    new Query<CommunityEntity>().getPage(params),
                    new QueryWrapper<CommunityEntity>()
                            .eq("delete_flag", 0)
                            .orderBy(true, false, "cj_time")
            );
            return new PageUtils(page);
        }
        IPage<CommunityEntity> page = this.page(
                new Query<CommunityEntity>().getPage(params),
                new QueryWrapper<CommunityEntity>()
                        .like("community_name", communityName)
                        .eq("delete_flag", 0)
                        .orderBy(true, false, "cj_time")
        );

        return new PageUtils(page);
    }
}